package com.example.demo.common;

import com.example.demo.util.AssertUtils;
import com.example.demo.util.DateUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * 保留两位小数格式化
 * yyyy-MM-dd
 */
public class LongToDateStringSerialize extends JsonSerializer<Long> {
    @Override
    public void serialize(Long date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
        if(AssertUtils.isNotNull(date)) {
            jsonGenerator.writeString(DateUtils.timeStrToString(date,DateUtils.FORMATE3));
        }
    }
}
